﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_Flow_BackManage_UpdateFlowStepSections : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SectionServices sectionServices=new SectionServices();
            List<Section> list = sectionServices.findAllSection();
            Flow_NewFlowStep nfs = Flow_NewFlowStep_Service.FindFlowStepById(Convert.ToInt32(Request.QueryString["fid"]));
            string[] sections = nfs.Prc_sections.Split(',');
            Label1.Text = "步骤"+nfs.Sort_id.ToString()+" - 编辑经办部门";
            foreach (Section s in list)
            {
                int state = 0;
                foreach (string var in sections)
                {
                    if (s.SectionId.ToString()==var)
                    {
                        lbManageSections.Items.Add(new ListItem(s.SectionName,s.SectionId.ToString()));
                        state = 1;
                        break;
                    }
                }
                if (state==0)
                {
                    lbSections.Items.Add(new ListItem(s.SectionName, s.SectionId.ToString()));
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string[] flowStepSections = Request.Form.GetValues("lbManageSections");
        string flowStepSectionstr = "";
        if (flowStepSections != null)
        {
            foreach (string var in flowStepSections)
            {
                flowStepSectionstr += var + ",";
            }
        }
        Flow_NewFlowStep nfs = new Flow_NewFlowStep();
        nfs.NewFlowStep_id = Convert.ToInt32(Request.QueryString["fid"]);
        nfs.Prc_sections = flowStepSectionstr;
        if (Flow_NewFlowStep_Service.UpdateFlowStepSections(nfs))
        {
            Response.Redirect("FlowStepList.aspx?id=" + Request.QueryString["id"]+"&pageIndex="+Request.QueryString["pageIndex"]);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(),"","alert('保存失败！请重试！')",true);
        }
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("FlowStepList.aspx?id=" + Request.QueryString["id"] + "&pageIndex=" + Request.QueryString["pageIndex"]);
    }
}
